package com.example.demo.imagemanage.controller;

import com.example.demo.imagemanage.service.ImageService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
@CrossOrigin
public class ImageController {
    @Autowired
    private ImageService imageService;


    /**
     * @Description 初始化页面，查询所有中心店面
     * @Author zhangxue
     * @Date 8:53 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/initImgPage",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String initPage( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(param.size()>=1){
            List<Map<String,Object>> resultList = imageService.queryAllStyle(param);
            List<Map<String,Object>> resultList2 = imageService.queryAllType(param);
            resultMap.put("data",resultList);
            resultMap.put("data2",resultList2);
            resultMap.put("status","1");
        }else{

            resultMap.put("status","0");
        }
        js = JSONObject.fromObject(resultMap);

        return js.toString();
    }




    /**
     * @Description 通过厂家和产品查询所有图片
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryImagesByFIDAndPID",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryImagesByFIDAndPID(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = imageService.queryImagesByFIDAndPID(param);
        return statusMap;
    }


    /**
         * @Description 查询厂家下拉框
         * @Author zhangxue
         * @Date 17:34 2018/7/11
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/changeFactory",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> changeFactory(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = imageService.changeFactory(param);
        return statusMap;
    }

    /**
     * @Description 查询产品下拉框
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/changeProduct",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> changeProduct(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = imageService.changeProduct(param);
        return statusMap;
    }

    /**
     * @Description 上传图片
     * @Author zhangxue
     * @Date 11:37 2018/7/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/uploadImage",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> uploadImage(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = imageService.uploadImage(param);
        return statusMap;
    }

    /**
     * @Description 通过风格和品类查询所有图片
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllImageByStyleAndType",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllImageByStyleAndType(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = imageService.queryAllImageByStyleAndType(param);
        return statusMap;
    }

    /**
         * @Description 通过ID删除图片
         * @Author zhangxue
         * @Date 15:16 2018/8/24
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delectImageByID",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delectImageByID(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = imageService.delectImageByID(param);
        return statusMap;
    }
}
